
let idDone:boolean = false;
console.log("wxq");
// let name: string = "Jacky";
// name = "Tom";
// name = 'Mick';

let list:Array<Number> = [1,2,3,4]

let x:[string,number];
x=["hello",10]

enum Color {Red, Green, Blue};

let c:Color.Red


let notSure: unknown = 4;
notSure = 'maybe a string instead';
notSure = false;

function test():void {
  console.log('This is function is void');
}
// Null 和 Undefined
let u:undefined= undefined;
let n:null=null;

// 联合类型
let myFavoriteNumber:string|number
myFavoriteNumber='wxq'
myFavoriteNumber=111

//条件语句
var num:number=5
if(num>0){
  console.log("shu.")
}


//if...else 语句

var num2:number=12
if(num2%2==0){

}else if (1){

}else{

}

var grade:string="A"

switch (grade){
  case "a":{

  }
  case 'b':{
   break
  }

}


function  add(x,y){

}

let myAdd= function(x,y){
  return x+y
}



// 有名函数：给变量设置为number类型
function add2(x: number, y: number): number {
  return x + y;
}

// 匿名函数：给变量设置为number类型
let myAdd2 = function (x: number, y: number): number {
  return x + y;
};

// 可选参数

function  buildName(firstName:string,lastname?:string){
  if(lastname){
    return firstName + ' ' + lastname;
  }else {
    return firstName;
  }
}

let result1 = buildName('Bob');
let result2 = buildName('Bob', 'Adams');

console.log(result1+result2)

// 剩余参数
function getEmployeeName(firstName:string,...resetOfName:string[]){
  return firstName + ' ' + resetOfName.join(' ');
}

// 箭头函数

function  testNumber(num:number){
  if(num>0){
    console.log(num + ' 是正数');
  }else if(num<0){
    console.log(num + ' 是负数');
  }else{
    console.log(num + ' 为0');
  }
}

let testArrowFun=(num:number)=>{
  if (num > 0) {
    console.log(num + ' 是正数');
    return "返回是正数";
  } else if (num < 0) {
    console.log(num + ' 是负数');
    return "返回是负数";
  } else {
    console.log(num + ' 为0');
    return "返回为0";
  }
}

testArrowFun(-1);

console.log(testArrowFun(1))

//类

class Person {
  private name:string
  private  age:number

  constructor(name:string,age:number) {
    this.name=name;
    this.age=age
  }


  public getPersonInfo(): string {
    return `My name is ${this.name} and age is ${this.age}`;
  }
}


let person1 = new Person('Jacky', 18);
person1.getPersonInfo();


class Employee extends  Person {
  private department: string

  constructor(name:string,age:number,department:string) {
    super(name,age)
    this.department = department;
  }

  public getEmployeeInfo(): string {
    return this.getPersonInfo() + ` and work in ${this.department}`;
  }
}


let person2 = new Employee('Tom', 28, 'HuaWei');
person2.getPersonInfo();
person2.getEmployeeInfo();

// 模块

export class NewsData{
  title:string;
  content: string;
  imagesUrl: Array<string>;
  source: string;

  constructor(title: string, content: string, imagesUrl: Array<string>, source: string) {
    this.title = title;
    this.content = content;
    this.imagesUrl = imagesUrl;
    this.source = source;
  }


}

// 迭代器
let somearray=[1,'string',false]

for(let entry of somearray){
  console.log(entry.toString())
}
let list2 = [4, 5, 6];

for (let list2Key in list2) {
  console.log(list2Key);
}

for (let i of list2) {
  console.log(i); // "4", "5", "6"
}